/**
 * Simple regex experiment to create an automatic emoticons by Taufik Nurrohman and modified by aiizahhblog-team, and thanks to indo.mt5 for the smilies
 * Visit: http://aiizahh.blogspot.com
 * Update: 23 April 2013
 */

$(function() {

	// Append an emoticon bar before comment-form
	if (putEmoAbove) {
		$(putEmoAbove).before('<div class="emoWrap"> dad deff depressed greedy dontcare order shake slap smoke spoiled support tired angry1 angry2 cheer cry4 drunk happy haii hmmm huhhh khekhe omg peace2 pleased wat2 wind</div>');
	}
	function emo(emo, imgRep, emoKey) {
		$(emoRange).each(function() {
			$(this).html($(this).html().replace(/<br ?\/?>(:|;|=|\^)/ig, "<br> $1").replace(emo, " <img src='" + imgRep + "' class='emo delayLoad' alt='" + emoKey + "' />"));
		});
	}
	emo(/\sdad/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/dad.gif", "dad");
	emo(/\sdeff/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/deff.gif", "deff");
	emo(/\sdepressed/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/depressed.gif", "depressed");
	emo(/\sgreedy/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/greedy.gif", "greedy");
	emo(/\sdontcare/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/idontcare.gif", "dontcare");
	emo(/\sorder/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/order.gif", "order");
	emo(/\sshake/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/shake.gif", "shake");
	emo(/\sslap/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/slap.gif", "slap");
	emo(/\ssmoke/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/smoke.gif", "smoke");
	emo(/\sspoiled/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/spoiled.gif", "spoiled");
	emo(/\ssupport/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/support.gif", "support");
	emo(/\stired/g, "http://aiizahh-reader.googlecode.com/svn/trunk/my%20emo/tired1.gif", "tired");
  emo(/\sangry1/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/angry1.gif", "angry1");
	emo(/\sangry2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/angry2.gif", "angry2");
	emo(/\scheer/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/cheer.gif", "cheer");
	emo(/\scry4/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/cry4.gif", "cry4");
	emo(/\sdrunk/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/drunk.gif", "drunk");
	emo(/\shappy/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/happy.gif", "happy");
	emo(/\shaii/ig, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/hi.gif", "haii");
	emo(/\shmmm/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/hmm.gif", "hmmm");
	emo(/\shuhhh/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/huhh.gif", "huhhh");
	emo(/\skhekhe/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/khekhe.gif", "khekhe");
	emo(/\somg/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/omg.gif", "omg");
	emo(/\speace2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/peace2.gif", "peace2");
  emo(/\spleased/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/pleased.gif", "pleased");
	emo(/\swat2/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/wat2.gif", "wat2");
	emo(/\swind/g, "http://aiizahh-reader.googlecode.com/svn/trunk/tambahan%20emo/wind.gif", "wind");


	var one = 0; // Show alert one times!

	// Click anywhere to hide the emoticon
	$(document.body).on("click", function() {
		$('.emoKey').remove();
	});

	// Click to show the code!
	$('.emo').css('cursor', 'pointer').on("click", function(e) {
		$('.emoKey').remove();
		$(this).after('<input class="emoKey" type="text" size="5" value=" ' + this.alt + '" />');
		$('.emoKey').trigger("select");
		if(emoMessage && one === 0) {
			alert(emoMessage);
			one = 1;
		}
		e.stopPropagation();
	});

});
